package com.jwiki.app.jkeeper.service.impl;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.jwiki.app.jkeeper.common.jdbc.JdbcUtils;
import com.jwiki.app.jkeeper.common.jdbc.Page;
import com.jwiki.app.jkeeper.controller.form.SearchForm;
import com.jwiki.app.jkeeper.repository.mapper.SearchMapper;
import com.jwiki.app.jkeeper.service.BaseService;
import com.jwiki.app.jkeeper.service.SearchService;

@Service
public class SearchServiceImpl extends BaseService implements SearchService {

    @Autowired
    private SearchMapper searchMapper;

    @Override
    public Page<Map<String, Object>> getResultByPage(SearchForm form) {
        Page<Map<String, Object>> page = JdbcUtils.build().orderBy(form.getOrderBy())
                .limit(form.getOffset(), form.getLimit()).getPage();
        page.setData(searchMapper.selectResult(form.getUserId(), form.getKeyword()));
        return page;
    }

}
